
 <template>
  <div class="wrap">
    <el-form
      :inline="true"
      :model="ruleform"
      ref="from"
      :rules="rules"
      class="demo-form-inline ip-form"
    >
      <el-form-item label="平台为网关分配的用户名 " prop="user_for_gateway">
        <el-input v-model="ruleform.user_for_gateway" message placeholder></el-input>
      </el-form-item>
      <el-form-item label="平台为网关分配的设备码 " prop="device_code_for_gateway">
        <el-input v-model="ruleform.device_code_for_gateway" message placeholder></el-input>
      </el-form-item>
      <el-form-item label="平台为网关分配的设备别名 " prop="alias">
        <el-input v-model="ruleform.alias" message placeholder></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="onSubmit('from')">注册</el-button>
        <el-button type="warning" plain @click="onReset('from')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
import { resetForm } from "@/utils/Tool";
export default {
  name: "",
  components: {},
  props: {},
  data() {
    return {
      ruleform: {
        user_for_gateway: "",
        device_code_for_gateway: "",
        alias: ""
      },
      rules: {
        user_for_gateway: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        device_code_for_gateway: [
          { required: true, message: "请输入设备码", trigger: "blur" }
        ],
        alias: [
          { required: true, message: "请输入设备别名", trigger: "blur" }
        ]
      }
    };
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    //添加 提交
    onSubmit(formName) {
      var that = this;
      that.$refs[formName].validate(valid => {
        if (valid) {
          postData("/adminweb/mwgateway/register", {
            user_for_gateway: that.ruleform.user_for_gateway,
            device_code_for_gateway: that.ruleform.device_code_for_gateway,
            alias: that.ruleform.alias,
          })
            .then(res => {
              that.$message.success("注册成功！");
              //刷新table
              that.$store.commit(
                "setSubmitData",
                Math.floor(Math.random() * 10000000)
              );
              let datas = resetForm(that.ruleform, thithats.$refs[formName]);
              that.ruleform = datas;
            })
            .catch(res => {
             that.$message.error(res.code + "，" + res.msg);
            });
        } else {
         that.$message.error("注册失败");
          return false;
        }
      });
    },
    //重置
    onReset(val) {
      this.$refs[val].resetFields();
    }
  },
  watch: {}
};
</script>
<style scoped>
.wrap {
  padding: 15px;
}
</style>
